import scala.io.Source

/**
  * @Description:
  * @author caoyangjie
  * @date 2020年01月2020/1/4日 15:52
  * @Copyright: © 赢时胜
  */
object PrintFormatFileLine {
  def widthWithLine(s:String):Int = s.length.toString.length

  def main(args:Array[String]){
    if(args.length>=1){
      val lines = Source.fromFile(args(0)).getLines.toList
      val maxLengthLine = lines.reduceLeft(
        (l1,l2) => if(l1.length>l2.length) l1 else l2
      )
      val maxWidth = widthWithLine(maxLengthLine)
      for(line<-lines){
        val numspaces = maxWidth-widthWithLine(line)
        val padding = " " * numspaces
        println(padding+line.length+"|"+line)
      }
    }else{
      println("请给定要格式化的文件路径")
    }

    echo("hello","world")
    val arr = Array("hello","world","?")
    echo(arr:_*)
  }

  def echo(words:String*) = for(word<-words) println(word)

}
